/**
 * \file  gui_params.cpp
 * \brief functions for the GUI.
 *
 * ASO: Antiviral Sequence Optimizer
 * <http://aso.googlecode.com/>
 * Copyright (C) 2010 Velez Ezequiel, Peralta Andres, FuDePAN
 *
 * This file is part of the ASO project.
 *
 * Contents:      Implementation file for GUI functions.
 *
 * System:         ASO
 * Language:       C++
 *
 * Author:         Velez Ezequiel, Peralta Andres
 * E-Mail:
 *
 * ASO is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * ASO is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with ASO.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include <ctime>
#include "inc/gui_params.h"

void gui_plugin(const ParameterList& paramList) throw(BadValue)
{
    if (!paramList.empty())
    {
        mili::CAutonomousIterator<ParameterList> it(paramList);
        std::cout << "Plugin Parameters: " << std::endl;
        std::cout << "-------------------" << std::endl;
        while (!it.end())
        {
            std::string aux;
            std::cout << (*it)->get_tag() << " : " << std::endl;
            std::cin >> aux;
            while (!(*it)->set_value(aux))
            {
                std::cout << "Bad Value for the Parameter" << std::endl;
                std::cout << (*it)->get_info() << std::endl;
                std::cin >> aux;
                //throw BadValue("Bad Value for the Parameter");
            }
            ++it;
        }
    }
}

void gui_help(const char* help_file)
{
    std::string help;
    std::ifstream infile(help_file);

    if (infile)
    {
        while (getline(infile, help))
        {
            std::cout << help << std::endl;
        }
    }
    else
        throw "File not found";
    infile.close();
}

static void gui_print_header(std::ofstream& toFile, const std::string& otherInfo)
{
    time_t runDate;
    time(&runDate);
    toFile << (ctime(&runDate)) << std::endl;
    toFile << ("------------------------------------------------------------") << std::endl;
    toFile << otherInfo << std::endl;
    toFile << ("------------------------------------------------------------") << std::endl;
    /*Se puede agregar más información si se quiere.*/
}

void gui_print_ranking(TherapyRanker& ranking, const std::string& output, const std::string& otherInfo)
{
    RankingIterator rankingIt(ranking);
    std::ofstream outFile(output.c_str(), std::ofstream::binary);
    size_t i = 1;
    gui_print_header(outFile, otherInfo);

    while (!rankingIt.end())
    {
        std::string line;
        (*rankingIt)->get_antivital_names(line);

        if (outFile != NULL)
        {
            outFile << "Therapy: " << i << std::endl;
            outFile << line << std::endl;
        }
        ++rankingIt;
        ++i;
    }
}








